 <link type="text/css" href="/admins/js/pagerView/pager-view.css" rel="stylesheet" />
<link type="text/css" href="/admins/js/jquery/css/ui-lightness/jquery-ui-1.8.20.custom.css" rel="stylesheet" />
<script type="text/javascript" src="/admins/js/jquery/jquery-ui-1.8.20.custom.min.js"></script>
<script type="text/javascript" src="/admins/js/jquery/jquery.ui.datepicker-zh-CN.js"></script>
<script type="text/javascript" src="/admins/js/pagerView/pager-view.js"></script>
<script type="text/javascript">
    $(function(){
    
        $.datepicker.setDefaults( $.datepicker.regional[ "zh-CN" ] );
        $( "#form1 #sel #starttime" ).datepicker({
            changeMonth: true,
            changeYear: true
        });
        $( "#form1 #sel #endtime" ).datepicker({
            changeMonth: true,
            changeYear: true
        });
    });
</script>



<!-- 弹出div CSS -->
<style type="text/css">
<!--
.mydiv {
background-color: #FFFFFF;
border: 1px solid #000000;
text-align: center;
line-height: 40px;
font-size: 12px;
z-index:999;/*优先级*/
width: 400px;
height: 50px;
left:50%;
top:50%;
margin-left:-150px!important;/*FF IE7 该值为本身宽的一半 ，!important的出现就是为了让用户自己设置被执行语句的优先级*/
margin-top:-60px!important;/*FF IE7 该值为本身高的一半*/
margin-top:0px;
position:fixed!important;/* FF IE7*/
position:absolute;/*IE6*/
}
.bg,.popIframe {

}
.popIframe {
filter:alpha(opacity=0);/*IE 设置透明度*/
opacity:0;/*FF*/
}
-->
</style>
<!-- 弹出div JS -->
<script language="javascript" type="text/javascript">
function showDiv(){
document.getElementById('popDiv').style.display='block';
document.getElementById('popIframe').style.display='block';
document.getElementById('bg').style.display='block';
}
function closeDiv(){
document.getElementById('popDiv').style.display='none';
document.getElementById('bg').style.display='none';
document.getElementById('popIframe').style.display='none';
}
</script>

<style>
	.datatable {
                width:90%;
		text-align: left;
		font-size: 12px;
		font-family: verdana;
		background: #c0c0c0; margin:2px;
	}

	.datatable thead tr,

	.datatable tfoot tr {
		background: #c0c0c0;
	}

	.datatable tbody tr {
		background: #f0f0f0;
                height: 30px;
	}
        
        .dataTable span{
            margin-left: 20px;
            font-size: 14px;
            vertical-align: middle;
        }
	#waybill-table td,#waybill-table th{
		border: 1px solid #000; 
                height:28px;
	}
	.datatable td {background-color:white;}
	
	.datatable .hover td {background-color:#99CCFF;}
	
	.datatable .select td {background-color:#EEEE99;}

	#ui-datepicker-div{ font-size:12px;}
</style>
<div style="padding:2px; margin:2px;" class="dataTable">
    <form action="/admini/managebuyshop/managebuyshop1/stus/<?php echo $this->status; ?>"  method="post" style="margin:0px" id="form1">
        <div style=" border:1px solid #DDDDDD; padding:2px; margin:2px;line-height: 36px;" id='sel'> 
            <label for="name">用户ID：</label><input type="text" id="userid" name="userid" value="<?php echo $this->userid;?>"/>
            <label for="orderno">订单号：</label><input type="text" id="orderno" name="orderno" value="<?php echo $this->orderno;?>"/>
            <label for="starttime">提交时间：</label><input type="text" id="starttime" name="starttime" value="<?php echo $this->starttime;?>" />
            <label for="endtime">-- </label><input type="text" id="endtime" name="endtime" value="<?php echo $this->endtime;?>"  />
            <label for="status">状态：</label>
            <select id="status" name="status">
                  <?php foreach ($this->arrsta as $key => $val){?>
                    <option value="<?php echo $key;?>" <?php if($this->status==$key){echo "selected";}?>><?php echo $val;?></option>
                  <?php }?>
                    <option value="" <?php if($this->status==""){echo "selected";}?>>所有</option>
            </select>
            <input type="submit" id="queryButton" name="queryButton" value="查询"/>
        </div>
    </form>

    <div id="shipInfo" style="display:none;width: 560px">
    物流信息加载中,请稍候...
</div>
    <table cellspacing="1" width="100%" border="1" class="datatable" id="waybill-table">
	<thead>
		<tr>
                        <th class="w0">宝贝信息</th>
                        <th class="w0">&nbsp;</th>
                        <th class="w1">单价</th>
			<th class="w1">数量</th>
                        <th class="w0">实付款</th>
                        <th class="w1">状态</th>
		</tr>
	</thead>
	<tbody >
                       
            <?php 
                    if( $this->buydetail != ''){
                    foreach ($this->buydetail as $Item) {
                        $shopdetail = $Item->shipdetail;
                ?>
            
                    <tr>
                        <td colspan="5" style="background-color: #DEF0FB;height: 20px;">
                            <span>订单编号：<?php echo $Item->orderid;?></span>
                            <span>时间：<?php echo $Item->dateCreated;?></span>
                            <span>用户ID：<?php echo $Item->userId;?></span>
                            <span>仓库号：<a href="/admini/manageuser/storedetail/id/<?php echo $Item->userId;?>" target="_blank" ><?php echo $Item->byuserdetail->storeno;?></a></span>
                            <span>昵称：<?php echo $Item->user->nikename;?></span>
                                
                            <span id="ShowOrHide<?php echo $Item->Id ?>" onclick="ShowOrHideProduct(<?php echo $Item->Id;?>,<?php echo count($shopdetail); ?>)" style="cursor:pointer">收起</span>
                        </td>
                        <td style="background-color: #DEF0FB;height: 20px;" align="center">
                            <a href="javascript:UpdateStatu(<?php echo $Item->id ?>)" ><div id="OperTitle<?php echo $Item->id ?>">
                            <?php 
                                            switch ($Item->status)
                                            {
                                                case 1:
                                                    echo '设为已受理';
                                                    break;
                                                case 2:
                                                    echo '设为等待卖家发货';
                                                    break;
                                                case 3:
                                                    echo '设为卖家已发货';
                                                    break;
                                                case 4:
                                                    echo '设为已入库';
                                                    break;
                                            }
                            ?>
                            </div></a>
                        </td>
                    </tr>
                    
                    
                    <?php echo "<tr id='tr_".$Item->Id."_1'>"; $index = 2;?>
                            <?php if($shopdetail != null){ 
                                foreach ($shopdetail as $key => $val) { 
                                    if(count($shopdetail)>1){ 
                                        if($key > 0){
                                            echo "</tr><tr id='tr_".$Item->Id."_$index'>";
                                            $index+=1;
                                        }
                                    }
                                    $productd = $val->byproductd;
                                    ?>
                        <td valign="middle" class="w0">
                            <div style="float:left;">
                                <a href="<?php echo $productd->remoteImage;?>" target="_blank"><img src="<?php echo $productd->remoteImage;?>" width="50px" height="50px" style="vertical-align:middle;"/></a>
                            </div>
                            <div style="float:left;color:#00f;">
                                &nbsp;&nbsp;<a href="<?php echo $productd->url;?>" target="_blank"><?php echo iconv_strlen($val->productName)>=50?mb_substr($val->productName,0,50, 'utf-8').'...':$val->productName;?></a>
                            </div><br>
                            <div style="float:left;color:#666;">&nbsp;&nbsp;<?php echo iconv_strlen($productd->PropertyAlias)>=50?mb_substr($productd->PropertyAlias,0,50, 'utf-8').'...':$productd->PropertyAlias;?></div>
                        </td>
                        
                        <td class="w1" align="center"><a href="javascript:AddRemarks(<?php echo $val->id;?>);" ><div id="Comment<?php echo $val->id;?>">添加说明</div></a></td>
                        
                        <td class="w1" align="center"><?php echo $val->price;?>
                            <?php if($val->status != 1) {?>
                                <a href="javascript:SingleRetuenMoney(<?php echo $val->id;?>,<?php echo $Item->userId; ?>);" >
                                    <div id="SingleRetuenMoney<?php echo $val->id;?>">单项退款</div>
                                <?php                                 
                                } 
                                else 
                                { ?>
                                    <div><font color="green">已退款</font></div>
                                <?php                                 
                                } 
                                ?>
                        </a>
                        </td>
                        <td class="w0" align="center"><?php echo $val->quantity;?></td>
                        <?php if($key == 0){?>
                            <td class="w1" rowspan="<?php echo count($Item->shipdetail);?>" align="center">￥<?php echo $Item->sum;?></td>
                            <td class="w0" rowspan="<?php echo count($Item->shipdetail);?>"align="center"><?php echo $Item->StatusText;?><br>
                               <?php if($Item->status != 11) {?>
                                <a href="javascript:ReturnMoney(<?php echo $Item->id;?>,<?php echo $Item->userId ?>)" >取消并退款</a>
                                <?php } else { ?>
                                
                                <?php } ?>
                            </td>
                            
                        <?php }}}?>
                    </tr>
                    
                        <tr>
                        <td colspan="6" style="background-color: #FFFFFF;height: 20px;">
                            淘宝订单编号：<input type="textbox" id="orderNo<?php echo $Item->id ?>" name="orderNo<?php echo $Item->id ?>" value="<?php echo $Item->orderNo; ?>" /> 物流单号：
                            <select name="logistics<?php echo $Item->id ?>" id="logistics<?php echo $Item->id ?>">
                            <?php foreach ($this->expresscomp as $expresscomp) {?>
                            <option value="<?php echo $expresscomp->name;?>" <?php if($expresscomp->name == $Item->logistics) echo "selected" ?>><?php echo $expresscomp->name;?></option>
                            <?php }?>
                            </select>
                            <input type="logisticsNo" id="logisticsNo<?php echo $Item->id ?>" name="logisticsNo<?php echo $Item->id ?>" value="<?php echo $Item->logisticsNo; ?>" /> <input type="button" id="btnLogistics<?php echo $Item->id ?>" name="btnLogistics<?php echo $Item->id ?>" onclick="javascript:UpdateLogistics(<?php echo $Item->id ?>)" value="更新" />
                        </td>
                    </tr>
                    <tr>
                        <td colspan="6">&nbsp;</td>
                    </tr>
                    
                    <?php 
                    }}
                    ?>
                	</tbody>
</table>

 <?php
    echo $this->partial('paging.phtml', array("pages" => $this->result,"pamas"=>"username=".$this->username."&storeno=$this->storeno&dateselect=$this->dateselect&starttime=$this->starttime&endtime=$this->endtime&status=$this->status"));        
?>
</div>


<div id="popDiv" class="mydiv" style="display:none;">
<table width="100%" height="100%" border="0">
    <tr height="100%">
        <td nowrap width="70px">&nbsp;添加说明：</td>
        <td width="320px" align="left" nowrap style="padding-right: 5px">
            <input type="hidden" id="hidCommentId" />            
            <input type="textbox" id="txtComment" name="txtComment" style="width:250px"></input>
            <input type="button" id="btnSubmitComment" value="提交" onclick="SubmitComment()"/>
            <input type="button" id="btnSubmitComment" value="关闭" onclick="closeDiv()"/>
        </td>
    </tr>
    
        </td>
    </tr>
    <tr heihght="10px">
        <td colspan="2" valign="top" align="right">&nbsp;</td>
    </tr>
</table>
</div>
<div id='popIframe' class='popIframe' frameborder='0' ></div>
</body>

<script type="text/javascript">
    $('#waybill-table #accept').on('click',function(){
       var id = $(this).attr('name');
       if(id == ''){
            alert("请选择订单");
            return false;
        }else{
            $.ajax({
                type: 'POST',
                url: '/admini/managebuyshop/accept/id/'+id,
                success: function(data) {
                    if(data == 1){
                        alert("受理成功");
                    }else if(data == 2){
                        alert("受理只接受已付款的订单");
                    }else{
                        alert("发生未知错误，请重新操作");
                    }
                    location.href='/admini/managebuyshop/index';
                }
            });
            
        }
    });
    $('#waybill-table #buyshop').on('click',function(){
       var id = $(this).attr('name');
       if(id == ''){
            alert("请选择订单");
            return false;
        }else{
            location.href='/admini/managebuyshop/buyshop/id/'+id;            
        }
    });
    $('#waybill-table #instore').on('click',function(){
       var id = $(this).attr('name');
       if(id == ''){
            alert("请选择订单");
            return false;
        }else{
            location.href='/admini/managestore/instore/id/'+id;            
        }
    });
    $('#waybill-table #shopout').on('click',function(){
       var id = $(this).attr('name');
       if(id == ''){
            alert("请选择订单");
            return false;
        }else{
            location.href='/admini/managebuyshop/shopout/id/'+id;            
        }
    });
    
    
    
    
    
    
    
    
    
    
    
    
    
    /**
     *商品收起、展开
     **/
    function ShowOrHideProduct(orderId, trId)
    {        
        for(var i=1; i<=trId; i++)
        {
            if(document.getElementById("tr_"+orderId+"_"+i).style.display == "none")
            {
                $("#tr_"+orderId+"_"+i).show();
                $("#ShowOrHide"+orderId).html("收起");
                $("OrderPrice"+orderId).attr("rowspan","0");
            }
            else
            {
                $("#tr_"+orderId+"_"+i).hide();
                $("#ShowOrHide"+orderId).html("展开");
                $("OrderPrice"+orderId).attr("rowspan",trId);
            }                
        }        
    }
    
    /**
     *提交说明
     */
    function SubmitComment()
    {
        var comment = $("#txtComment").val();
        var id = $("#hidCommentId").val();
        if(comment == '')
        {
            alert("请输入说明信息.");
            return;
        }
        
        $("#btnSubmitComment").html('提交中...');
        $.ajax({
                type: 'POST',
                url: '/admini/managebuyshop/updateorderitemcomment/id/'+id+'/comment/'+comment,
                success: function(data) {
                    if(data == 1){
                        alert("提交成功");
                        $("#btnSubmitComment").html('提交');
                        closeDiv();
                    }else{
                        alert("发生未知错误，请重新操作");
                    }
                }
            });
    }
    
    /**
    *添加说明
    */
    function AddRemarks(id)
    { 
        $("#hidCommentId").val(id);
        
        $.ajax({
                type: 'POST',
                url: '/admini/managebuyshop/getcomment/id/'+id,
                success: function(data) {
                    $("#txtComment").val(data);
                }
            });
            
        showDiv();
    }
    
    /**
    *更改状态
    */
    function UpdateStatu(orderId,statu)
    {
        var statu = <?php echo $this->stype?>;

        $("#OperTitle"+orderId).html('设置中...');
        $.ajax({
                type: 'POST',
                url: '/admini/managebuyshop/updatestatu/orderId/'+orderId+'/statu/'+statu,
                success: function(data) {
                    if(data == 1){
                        alert("设置成功");
                    }else{
                        alert("发生未知错误，请重新操作");
                    }
                    location.href='/admini/managebuyshop/managebuyshop1/stus/<?php echo $this->status?>';
                }
            });        
    }
    
    /**
    *更改物流信息
    */
    function UpdateLogistics(id)
    {
        var orderNo = $("#orderNo"+id).val();
        var logistics = $("#logistics"+id).val();
        var logisticsNo = $("#logisticsNo"+id).val();
        
        $("#btnLogistics"+id).val('更新中...');
        $.ajax({
                type: 'POST',
                url: '/admini/managebuyshop/updatelogistics/id/'+id+'/orderNo/'+orderNo+'/logistics/'+logistics+'/logisticsNo/'+logisticsNo,
                success: function(data) {
                    if(data == 1){
                        alert("设置成功");
                        $("#btnLogistics"+id).val('更新成功');
                    }else{
                        alert("发生未知错误，请重新操作");
                    }
                    location.href='/admini/managebuyshop/managebuyshop1/stus/<?php echo $this->status?>';
                }
            });
    }
    
    /**
     * 单个商品退款
     */
    function SingleRetuenMoney(id, userid)
    {
        $.ajax({
                type: 'POST',
                url: '/admini/managebuyshop/singleretuenmoney/id/'+id+'/userid/'+userid,
                success: function(data) {
                    if(data == 1){
                        alert("退款成功");   
                    }else{
                        alert("发生未知错误，请重新操作");
                    }
                    location.href='/admini/managebuyshop/managebuyshop1/stus/<?php echo $this->status?>';
                }                
            });
    }
    
    /**
     * 整个订单退款
     */
    function ReturnMoney(id, userid)
    {
        $.ajax({
                type: 'POST',
                url: '/admini/managebuyshop/retuenmoney/id/'+id+'/userid/'+userid,
                success: function(data) {
                    if(data == 1){
                        alert("退款成功");   
                    }else{
                        alert("发生未知错误，请重新操作");
                    }
                    location.href='/admini/managebuyshop/managebuyshop1/stus/<?php echo $this->status?>';
                }                
            });
    }
    
    
    
</script>
